if (EXISTS "${CURRENT_BUILDTREES_DIR}/src/.git")
    file(REMOVE_RECURSE ${CURRENT_BUILDTREES_DIR}/src)
endif()

kmpkg_from_gitee(
        OUT_SOURCE_PATH SOURCE_PATH
        REPO kumo-pub/ktest
        REF v${VERSION}
        SHA512 48bc57c94620e65dff2365ac09520d361b777f2ad4ad11fbe11f380fc4a0abeaa89b4710df35c3dfb23d86fcc4a49712227cd6243dbef316cc98a3fbf2dca4d4
        HEAD_REF master
)

string(COMPARE EQUAL "${KMPKG_CRT_LINKAGE}" "dynamic" KTEST_FORCE_SHARED_CRT)

kmpkg_cmake_configure(
    SOURCE_PATH ${SOURCE_PATH}
    OPTIONS
        -DBUILD_KMOCK=ON
        -DCMAKE_CXX_STANDARD=17
        -Dktest_force_shared_crt=${KTEST_FORCE_SHARED_CRT}
)

kmpkg_cmake_install()
kmpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/KTest)

file(
    INSTALL
        "${SOURCE_PATH}/kumotest/src/ktest.cc"
        "${SOURCE_PATH}/kumotest/src/ktest_main.cc"
        "${SOURCE_PATH}/kumotest/src/ktest-all.cc"
        "${SOURCE_PATH}/kumotest/src/ktest-assertion-result.cc"
        "${SOURCE_PATH}/kumotest/src/ktest-death-test.cc"
        "${SOURCE_PATH}/kumotest/src/ktest-filepath.cc"
        "${SOURCE_PATH}/kumotest/src/ktest-internal-inl.h"
        "${SOURCE_PATH}/kumotest/src/ktest-matchers.cc"
        "${SOURCE_PATH}/kumotest/src/ktest-port.cc"
        "${SOURCE_PATH}/kumotest/src/ktest-printers.cc"
        "${SOURCE_PATH}/kumotest/src/ktest-test-part.cc"
        "${SOURCE_PATH}/kumotest/src/ktest-typed-test.cc"
    DESTINATION
        ${CURRENT_PACKAGES_DIR}/src
)

file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)

kmpkg_fixup_pkgconfig()
if(NOT DEFINED KMPKG_BUILD_TYPE OR KMPKG_BUILD_TYPE STREQUAL "debug")
    kmpkg_replace_string("${CURRENT_PACKAGES_DIR}/lib/pkgconfig/kmock_main.pc" "libdir=\${prefix}/lib" "libdir=\${prefix}/lib/manual-link")
    kmpkg_replace_string("${CURRENT_PACKAGES_DIR}/lib/pkgconfig/ktest_main.pc" "libdir=\${prefix}/lib" "libdir=\${prefix}/lib/manual-link")
endif()
if(NOT DEFINED KMPKG_BUILD_TYPE OR KMPKG_BUILD_TYPE STREQUAL "debug")
    kmpkg_replace_string("${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/kmock_main.pc" "libdir=\${prefix}/lib" "libdir=\${prefix}/lib/manual-link")
    kmpkg_replace_string("${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/ktest_main.pc" "libdir=\${prefix}/lib" "libdir=\${prefix}/lib/manual-link")
endif()
kmpkg_copy_pdbs()

file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)

file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
